package com.databuff;

import com.googlecode.aviator.AviatorEvaluator;
import com.googlecode.aviator.runtime.JavaMethodReflectionFunctionMissing;

/**
 * @package com.databuff
 * @company: dacheng
 * @author: zlh
 * @createDate: 2022/3/21
 */
public class AviatorTest {
    public static void main(String[] args) {
        // 启用基于反射的方法查找和调用
        AviatorEvaluator.setFunctionMissing(JavaMethodReflectionFunctionMissing.getInstance());
        // 调用 String#indexOf
        System.out.println(AviatorEvaluator.execute("indexOf('hello world', 'w')"));
        // 调用 Long#floatValue
        System.out.println(AviatorEvaluator.execute("floatValue(3)"));
        // 调用 BigDecimal#add
        System.out.println(AviatorEvaluator.execute("add(3M, 4M)"));
        System.out.println(AviatorEvaluator.execute("3>1 && 2!=4 || true"));
        System.out.println(AviatorEvaluator.execute("(1+2+3)/2.0"));

        String aaa = "asdsfkdanf[kd今]年几岁的[你]";
        String bb = aaa.replaceAll("]$","");
        int i = bb.lastIndexOf("[");
        if (i > 0) {
            System.out.println(bb.substring(0, i));
            System.out.println(bb.substring(i + 1));
        }
        System.out.println(aaa);
        System.out.println(bb);


    }
}
